package com.hnucm.chapter5_2;

import androidx.appcompat.app.AppCompatActivity;

import android.app.BackgroundServiceStartNotAllowedException;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.Toast;

import com.hnucm.chapter5_2.utils.MyConstants;
import com.hnucm.chapter5_2.utils.ProcessUtil;

public class BaseActivity extends AppCompatActivity {

    private final static String TAG="BaseActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);
        Log.d(TAG, "onCreate: ");
//        Toast.makeText(BaseActivity.this, ProcessUtil.getCurrentProcessNameByApplication(),Toast.LENGTH_SHORT).show();

        findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_notification);
                remoteViews.setTextViewText(R.id.msg, "msg from process:"+Process.myPid()+"");
                remoteViews.setImageViewResource(R.id.icon,R.drawable.ic_icon);
//        PendingIntent pendingIntent = PendingIntent.getActivity(this,
//                0, new Intent(this, DemoActivity_1.class), PendingIntent.FLAG_UPDATE_CURRENT);
                PendingIntent openActivity2PendingIntent = PendingIntent.getActivity(
                        BaseActivity.this, 0, new Intent(BaseActivity.this, BaseActivity.class), PendingIntent.FLAG_IMMUTABLE);
//        remoteViews.setOnClickPendingIntent(R.id.item_holder, pendingIntent);
                remoteViews.setOnClickPendingIntent(R.id.open_activity2, openActivity2PendingIntent);
                Intent intent = new Intent(MyConstants.REMOTE_ACTION);
                intent.putExtra(MyConstants.EXTRA_REMOTE_VIEWS, remoteViews);
                sendBroadcast(intent);
                finish();
            }
        });
    }
}